const formatTime = date => { // 格式化时间（YYYY/MM/dd HH:mm:ss）
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return [year, month, day].map(formatMonthNumber).join('/') + ' ' + [hour, minute, second].map(formatMonthNumber).join(':')
}
const getNowYMD = () => { // 获取当前时间（YYYY/MM/dd）
  const year = new Date().getFullYear()
  const month = new Date().getMonth() + 1
  const day = new Date().getDate()
  return year + "-" + month + "-" + day
}
const indexSearchDate = () => {
  const data = new Array()
  const year = new Date().getFullYear()
  const month = new Date().getMonth() + 1
  for(var i=1;i>=0;i--){
    const info = {}
    if(i != 0){
      info.year = year - i
      const months = new Array()
      for(var j=0;j<12;j++ ){
        months.push(j+1)
      }
      info.month = months
    } else {
      info.year = year - i
      const months = new Array()
      for(var j=0;j<month;j++ ){
        months.push(j+1)
      }
      info.month = months
    }
    data.push(info)
  }
  return data
}

const formatMonthNumber = n => { // 月份补零
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatMonthNumber: formatMonthNumber,
  formatTime: formatTime,
  getNowYMD: getNowYMD,
  indexSearchDate: indexSearchDate
}
